<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * User Controller
 * 
 * Handles everything that has to do with a user.
 * Primarily used for the user profile, showing a users recipes
 * etc.
 * 
 * @package     Controllers
 * @author      Lukas Fritsch <jejanim@gmail.com>
 * @version     0.1 (06.08.2013)
 */ 

class User extends CPT_Controller{
    
    public function __construct(){
        parent::__construct();
    }
    
    /*
     * INDEX
     * This method is called whenever a user calls the controller
     * without any second segment (thats a method).
     * If this controller is called w/o further methods, we
     * show the calling users profile instead.
     */
    public function index(){
        $this->set_content_view('user/details');
	$this->details($this->tank_auth->get_user_id());
    }
        
    /*
     * DETAILS
     * Shows the users profile.
     * Redirects to home in case of missing parameter.
     * 
     * @param int $user_id 
     */
    public function details($user_id = FALSE){	
        if(!$user_id)                                                           #param missing, redirect to home
            redirect('start');
        
        $this->load->model('usermodel');
        $this->load->model('drinkmodel');
        $this->view_data['user']['details']   = $this->usermodel->get_details($user_id);
        $this->view_data['user']['drinks']    = $this->drinkmodel->get_user_drinks($user_id);
    }
}

